package com.lkxx.entity.converter;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.StringUtils;
import org.apache.poi.util.StringUtil;

import java.util.Date;
import java.util.Objects;

/**
 * @Author: lkxx [mazhenjun.lk.xx@gmail.com]
 * @CreateTime: 2023-11-01  17:21
 * @Description: 字符串转Date对象
 * @Version: 1.0
 */
public class StringToDateConverter implements Converter<Date> {
    @Override
    public Date convertToJavaData(ReadConverterContext<?> context) throws Exception {
        String stringValue = context.getReadCellData().getStringValue();
        if (stringValue != null && !stringValue.isEmpty()) {
            DateTime dateTime = DateUtil.parseDateTime(stringValue);
            return dateTime;
        }
        return null;
    }
}
